package com.xinfu.newproject.adapter.park_adapter;


import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.xinfu.newproject.R;
import com.xinfu.newproject.bean.pay.bean.PayRecordHeadBean;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * https://github.com/CymChad/BaseRecyclerViewAdapterHelper
 */
public class PaymentRecordsAdapter extends BaseSectionQuickAdapter<PayRecordHeadBean, BaseViewHolder> {
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param sectionHeadResId The section head layout id for each item
     * @param layoutResId      The layout resource id of each item.
     * @param data             A new list is created out of this one to avoid mutable list
     */
    public PaymentRecordsAdapter(int layoutResId, int sectionHeadResId, List data) {
        super(layoutResId, sectionHeadResId, data);
    }

    @Override
    protected void convertHead(BaseViewHolder helper, final PayRecordHeadBean item) {

        helper.setText(R.id.item_payment_records_head_tv, item.header);
//        helper.setVisible(R.id.more, item.isMore());
//        helper.addOnClickListener(R.id.more);
    }


    @Override
    protected void convert(BaseViewHolder helper, PayRecordHeadBean item) {
        JSONObject object = item.t;

        try {
            if (object.getString("typeName").contains("物业费")) {
                helper.setImageResource(R.id.item_payment_records_content_iv, R.mipmap.property_item_icon);
                helper.setText(R.id.item_payment_records_content_cost_type, "物业费");
            } else if (object.getString("typeName").contains("维修费")) {
                helper.setImageResource(R.id.item_payment_records_content_iv, R.mipmap.car_item_icon);
                helper.setText(R.id.item_payment_records_content_cost_type, "维修费");
            } else if (object.getString("billsRemarks").contains("停车费")) {
                helper.setImageResource(R.id.item_payment_records_content_iv, R.mipmap.car_item_icon);
                helper.setText(R.id.item_payment_records_content_cost_type, "停车费");
            }
            helper.setText(R.id.item_payment_records_content_cost_time, object.getString("payTime"));
            helper.setText(R.id.item_payment_records_content_cost_price, object.getString("payFee"));

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }


}
